﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JWFW.APISafe;

namespace JWFW.SFL
{
    /// <summary>
    /// 利用API函数实现的一些常用功能
    /// </summary>
    public class APIOP
    {
        /// <summary>
        /// 获取windows当前具有焦点的控件，可以是其他程序的
        /// </summary>
        /// <returns></returns>
        public IntPtr GetFocusControl()
        {
            IntPtr aim = API.GetForegroundWindow();
            uint fromid = API.GetCurrentThreadId();
            uint toid = API.GetWindowThreadProcessId(aim, (uint)IntPtr.Zero);
            API.AttachThreadInput(toid, fromid, true);
            IntPtr res = API.GetFocus();
            API.AttachThreadInput(toid, fromid, false);
            return res;
        }
    }
}
